package com.goldgov.statistics.lddylearnchart.web;

import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.goldgov.kcloud.core.json.JsonQueryObject;
import com.goldgov.learnmanage.service.Course;
import com.goldgov.learnmanage.service.CourseQuery;
import com.goldgov.learnmanage.service.CourseService;
import com.goldgov.learnmanage.service.User;
import com.goldgov.learnmanage.service.UserQuery;
import com.goldgov.utils.DateUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/workbench/statistics/lddylearnchart")
@Api("流动党员学习统计接口")
public class LddyLearnChartController {
	@Autowired
	private CourseService courseService;
	@GetMapping("/findPersonLearnTime")
	@ApiOperation(value = "个人学习时长", notes = "个人学习时长")
	public JsonQueryObject<User> findPersonLearnTime( UserQuery query,HttpServletRequest request,HttpServletResponse response) throws Exception {
		if (query.getSearchYear() == null || "".equals(query.getSearchYear())) {
			query.setSearchYear(String.valueOf(DateUtil.getYear(new Date())));
		}
		List<User> list=courseService.findPersonLearnTime(query);
		query.setResultList(list);
		return new JsonQueryObject<>(query);
	}
	@GetMapping("/findOrgAvgLearnTime")
	@ApiOperation(value = "支部平均学习时长", notes = "支部平均学习时长")
	public JsonQueryObject<Course> findOrgAvgLearnTime( CourseQuery query,HttpServletRequest request,HttpServletResponse response) throws Exception {
		if (query.getSearchYear() == null || "".equals(query.getSearchYear())) {
			query.setSearchYear(String.valueOf(DateUtil.getYear(new Date())));
		}
		List<Course> list=courseService.findOrgAvgLearnTime(query);
		query.setResultList(list);
		return new JsonQueryObject<>(query);
	}
}
